package com.ppt.android.common.bean

import android.os.Parcelable
import com.ppt.android.base.utils.DateUtils
import kotlinx.parcelize.Parcelize
import java.math.BigDecimal
import java.math.RoundingMode
import java.text.DecimalFormat
import kotlin.math.roundToInt

/**
 *
 * @author ZouJiaCai
 * @since 2023/4/10 15:35
 */
@Parcelize
data class UserInfo(
    /** 注册时间 */
    val createTime: String,
    /** 冻结状态 */
    val freezeStatus: Boolean,
    /** 用户id */
    val id: Int,
    /** 是否区代理 */
    val isAreaAgent: Boolean,
    /** 是否市代理 */
    val isCityAgent: Boolean,
    /** 是否推荐官 */
    val isReference: Boolean,
    /** 登录名称 */
    val loginName: String,
    /** 上级推荐官Id */
    val parentId: String?,
    /** 上级推荐官 */
    val parentReference: String?,
    /** 手机号 */
    val phoneNum: String,
    /** 推荐区域名称 */
    val referenceName: String?,
    /** 成为推荐官时间 */
    val referenceTime: String?,
    /** 成为代理时间 */
    val proxyTime: String?,
    /** 用户名 */
    val userName: String,
    /** 头像 */
    val avatar: String,
    /** 推送type */
    val type: String,
    /** 推送alias */
    val alias: String,
    /** 代理区域 */
    val areaName: String?,
    /** 联系人 */
    val contactName: String?,
    /** 角色为代理/代理+推荐官时使用此字段 */
    val agentName: String?,

    /** 是否默认消费区域 */
    val isConsumeDefault: Boolean = false,
    /** 消费区域名称 */
    val consumeAreaName: String? = null,

    /** 是否开启消费区域 */
    val isOpenConsume: Boolean = false,

    /** 是否默认支付密码 */
    val isPayDefault: Boolean = false,

    /** 我的积分余额*/
    val integralBalance: String? = "0"
) : Parcelable {
    @JvmName("integralBalance")
    fun getIntegralBalance(): String{
        if (integralBalance != null){
            try {
                val number = integralBalance.toDoubleOrNull()?.roundToInt() ?: 0
                val dNumber =  number / 100.0
                val decimalFormat = DecimalFormat("#.00")
                decimalFormat.roundingMode = RoundingMode.FLOOR
                val formattedNumber = decimalFormat.format(dNumber)
                val bd = BigDecimal(formattedNumber)
                return bd.stripTrailingZeros().toPlainString()
            }catch (e: Exception){
                e.printStackTrace()
                return "0"
            }
        }
        return "0"
    }

}

data class ProviderInfo(
    val area: String,
    val auditStatus: Int,
    val businessLicence: String,
    val businessScope: String,
    val category: Any?,
    val city: String,
    val contactName: String,
    val corporation: String,
    val createBy: Int,
    val createTime: Long?,
    val deleted: Boolean,
    val detailAddress: String,
    val freezeStatus: Boolean,
    val id: Int,
    val idCard: String,
    val name: String,
    val paging: Any?,
    val perfectStatus: Boolean,
    val phoneNum: String,
    val providerAgentId: Int,
    val providerAgentName: String?,
    val providerMcnId: Int?,
    val providerServiceId: Any?,
    val province: String,
    val serviceSigning: ServiceSigning?,
    val tiktokLifeId: String,
    val tiktokLifeName: Any?,
    val unifiedSocialCreditCode: String?,
    val updateBy: Any?,
    val updateTime: Any?,
    val version: Int,
    // 市场经理及机构才有此字段
    val identityCode: String?,
    val providerMcnName: String?,
    val parentName: String?,
    /**
     * 代理商角色独有字段
     * 是否允许子账号登录 true:允许   false：禁止
     */
    val openSub: Boolean?,
    /** 业务员 */
    val subAgentName: String
){
    @JvmName("providerAgentName")
    fun getProviderAgentName(): String {
        return providerAgentName?: "--"
    }

    @JvmName("providerMcnName")
    fun getProviderMcnName(): String {
        return providerMcnName?: "--"
    }

    @JvmName("createTime")
    fun getCreateTime(): String{
        var timestamp = 0L
        return  if (createTime != null){
            createTime.let {
                timestamp = if (it.toString().length == 10) it * 1000 else it
            }
            DateUtils.getDateFormatString(timestamp,"yyyy-MM-dd")
        } else{
            return  "无"
        }
    }

}

data class ServiceSigning(
    val chargeType: Int,
    val commissionRatio: String?,
    val createBy: Int,
    val createTime: Long,
    val deleted: Boolean,
    val endTime: Int,
    val id: Int,
    val merchantName: String,
    val orderId: String,
    val orderStatus: Int,
    val paging: Any?,
    val productName: String,
    val providerAgentId: Int,
    val providerMcnId: Int,
    val signingPlatform: Int,
    val startTime: Int,
    val tiktokLifeId: String,
    val updateBy: Any?,
    val updateTime: Any?,
    val version: Int
)